package cn.tansanqinger.controller.topic;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import cn.tansanqinger.service.topic.ITopicService;
import cn.tansanqinger.util.Tools;

@RequestMapping("/admin/topic")
@Controller
public class TopicUpdataController {
	
	@Autowired
	private ITopicService service;

	@RequestMapping("/list")
	public ModelAndView list(HttpServletRequest request, ModelAndView mv) {
		mv.setViewName("topic/list");
		return mv;
	}
	
	@RequestMapping("/addTopic")
	@ResponseBody
	public Map<String , Object> addKnowledge(HttpServletRequest request) {
		return service.add(request);
	}
	
	/**
	 * 编辑信息
	 * @param request
	 * @param mv
	 * @return
	 */
	@RequestMapping("/edit")
	public ModelAndView edit(HttpServletRequest request, ModelAndView mv) {
		mv.addObject("topic", service.selectIdOne(Tools.isEmpty(request.getParameter("id"))));
		mv.setViewName("topic/edit");
		return mv;
	}
	
	/**
	 * 修改信息
	 * @param request
	 * @return
	 */
	@RequestMapping("/modification")
	@ResponseBody
	public Map<String, Object> modification(HttpServletRequest request){
		return service.modification(request);
	}
}
